package top.hidoctor.auscultation.net.p;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;

import com.tang.base.BaseResponse;
import com.tang.base.NetMapEncryptUtils;
import com.tang.net.SuccessConsumer;
import com.tang.user.UserInfoManager;

import java.util.Map;

import io.reactivex.functions.Consumer;
import top.hidoctor.auscultation.bean.LabelListBean;
import top.hidoctor.auscultation.net.PresenterWrapper;
import top.hidoctor.auscultation.net.c.LabelListContract;
import top.hidoctor.auscultation.net.req.LabelReq;

public class LabelListPresenter extends PresenterWrapper<LabelListContract.View> implements LabelListContract.Presenter {


    public LabelListPresenter(Context context, LabelListContract.View view) {
        super(context, view);
    }

    @Override
    public void getList(LabelReq req, SwipeRefreshLayout refreshLayout) {
        if (refreshLayout != null && !refreshLayout.isRefreshing()) {
            mView.showLoading();
        }
        final Map<String, Object> map = new NetMapEncryptUtils(req).getMaps();
        map.put("userId", UserInfoManager.getInstance().getUserInfo().getUserId());
        add(mService.labelList(map)
                .compose(this.<LabelListBean>getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<LabelListBean>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<LabelListBean> response) {
                        mView.hideLoading();
                        mView.getListSuc(response.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }
}
